package com.ruoyi.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.order.domain.SrvServiceform;
import com.ruoyi.order.service.ISrvServiceformService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务单
Controller
 * 
 * @author ruoyi
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/serviceform")
public class SrvServiceformController extends BaseController
{
    @Autowired
    private ISrvServiceformService srvServiceformService;

    /**
     * 查询服务单列表
     */
    @PreAuthorize(hasPermi = "system:serviceform:list")
    @GetMapping("/list")
    public TableDataInfo list(SrvServiceform srvServiceform)
    {
        startPage();
        List<SrvServiceform> list = srvServiceformService.selectSrvServiceformList(srvServiceform);
        return getDataTable(list);
    }

    /**
     * 导出服务单列表
     */
    @PreAuthorize(hasPermi = "system:serviceform:export")
    @Log(title = "服务单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrvServiceform srvServiceform) throws IOException
    {
        List<SrvServiceform> list = srvServiceformService.selectSrvServiceformList(srvServiceform);
        ExcelUtil<SrvServiceform> util = new ExcelUtil<SrvServiceform>(SrvServiceform.class);
        util.exportExcel(response, list, "serviceform");
    }

    /**
     * 获取服务单详细信息
     */
    @PreAuthorize(hasPermi = "system:serviceform:query")
    @GetMapping(value = "/{srvSfcode}")
    public AjaxResult getInfo(@PathVariable("srvSfcode") String srvSfcode)
    {
        return AjaxResult.success(srvServiceformService.selectSrvServiceformById(srvSfcode));
    }

    /**
     * 新增服务单

     */
    @PreAuthorize(hasPermi = "system:serviceform:add")
    @Log(title = "服务单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrvServiceform srvServiceform)
    {
        return toAjax(srvServiceformService.insertSrvServiceform(srvServiceform));
    }

    /**
     * 修改服务单

     */
    @PreAuthorize(hasPermi = "system:serviceform:edit")
    @Log(title = "服务单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrvServiceform srvServiceform)
    {
        return toAjax(srvServiceformService.updateSrvServiceform(srvServiceform));
    }

    /**
     * 删除服务单

     */
    @PreAuthorize(hasPermi = "system:serviceform:remove")
    @Log(title = "服务单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{srvSfcodes}")
    public AjaxResult remove(@PathVariable String[] srvSfcodes)
    {
        return toAjax(srvServiceformService.deleteSrvServiceformByIds(srvSfcodes));
    }
}
